package cn.itsource.controller.app;

import cn.dev33.satoken.stp.StpUtil;
import cn.itsource.pojo.domain.CustomerCar;
import cn.itsource.result.JSONResult;
import cn.itsource.service.ICustomerCarService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;

@Tag(name = "客户车辆",description = "客户车辆")
@RestController
@RequestMapping("/app/customerCar")
public class AppCustomerCarController {

    @Autowired
    public ICustomerCarService customerCarService;

    @Operation( summary= "添加车辆",description = "添加车辆")
    @PostMapping(value = "/add")
    public JSONResult add(@RequestBody @Valid CustomerCar car){
        car.setCreateTime(new Date());
        car.setCustomerId(StpUtil.getLoginIdAsLong());
        return JSONResult.success(customerCarService.save(car));
    }



    //获取列表:PageQueryWrapper作为通用的查询对象
    @Operation( summary= "查询当前乘客的车辆列表",description = "查询当前乘客的车辆列表")
    @PostMapping(value = "/list/current")
    public JSONResult listForCurrent(){
        LambdaQueryWrapper<CustomerCar> query = new LambdaQueryWrapper<CustomerCar>()
                .eq(CustomerCar::getCustomerId, StpUtil.getLoginIdAsLong());
        return JSONResult.success(customerCarService.list(query));
    }



}
